package com.ecommerce.order.dto;

import com.ecommerce.order.entity.Order;
import com.ecommerce.order.entity.OrderItem;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 订单MapStruct映射接口
 */
@Mapper(componentModel = "spring")
public interface OrderMapper {

    /**
     * 映射器实例
     */
    OrderMapper INSTANCE = Mappers.getMapper(OrderMapper.class);

    /**
     * 实体转响应DTO
     * @param order 订单实体
     * @return 订单响应DTO
     */
    @Mapping(target = "statusText", ignore = true)
    @Mapping(target = "paymentMethodText", ignore = true)
    OrderResponse entityToResponseDto(Order order);

    /**
     * 实体列表转响应DTO列表
     * @param orders 订单实体列表
     * @return 订单响应DTO列表
     */
    List<OrderResponse> entityToResponseDtoList(List<Order> orders);

    /**
     * 订单项实体转响应DTO
     * @param orderItem 订单项实体
     * @return 订单项响应DTO
     */
    OrderItemResponse orderItemEntityToResponseDto(OrderItem orderItem);

    /**
     * 订单项实体列表转响应DTO列表
     * @param orderItems 订单项实体列表
     * @return 订单项响应DTO列表
     */
    List<OrderItemResponse> orderItemEntityToResponseDtoList(List<OrderItem> orderItems);

    /**
     * 获取订单状态描述
     * @param status 订单状态
     * @return 订单状态描述
     */
    default String getStatusText(Integer status) {
        if (status == null) {
            return "";
        }
        switch (status) {
            case 0:
                return "待付款";
            case 1:
                return "待发货";
            case 2:
                return "已发货";
            case 3:
                return "已完成";
            case 4:
                return "已取消";
            case 5:
                return "退款中";
            case 6:
                return "已退款";
            default:
                return "";
        }
    }

    /**
     * 获取支付方式描述
     * @param paymentMethod 支付方式
     * @return 支付方式描述
     */
    default String getPaymentMethodText(Integer paymentMethod) {
        if (paymentMethod == null) {
            return "";
        }
        switch (paymentMethod) {
            case 1:
                return "微信支付";
            case 2:
                return "支付宝";
            case 3:
                return "银行卡";
            default:
                return "";
        }
    }
}